package cn.icast.netty.c3;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.string.StringEncoder;

import java.net.InetSocketAddress;

public class EventLoopClient {
    public static void main(String[] args) throws InterruptedException {
        //启动类
        Channel channel = new Bootstrap()

                 //boss 和 worker
                 .group(new NioEventLoopGroup())
                 // 添加客户端channel实现
                 .channel(NioSocketChannel.class)
                 //添加处理器
                 .handler(new ChannelInitializer<NioSocketChannel>() {
                     @Override
                     protected void initChannel(NioSocketChannel ch) throws Exception {
                         ch.pipeline().addLast(new StringEncoder());
                     }

                 })
                 .connect(new InetSocketAddress("localhost",8080))
                 .sync()
                 .channel();
        System.out.println(channel);
        System.out.println("");

    }
}
